package com.gushenge.core

import android.os.Build
import android.util.Log
import com.gushenge.core.dao.MMKVConsts
import okhttp3.Interceptor
import okhttp3.Request
import okhttp3.Response
import java.io.IOException


class HeadInterceptor( ) :
    Interceptor {
    @Throws(IOException::class)
    override fun intercept(chain: Interceptor.Chain): Response {
        val builder: Request.Builder = chain.request()
            .newBuilder()



        if (   getAppInfo().isNotEmpty()) {
            val keys =  getAppInfo().keys
            for (headerKey in keys) {
                getAppInfo()[headerKey]?.let { builder.addHeader(headerKey, it).build() }
            }
        }
        //请求信息
        return chain.proceed(builder.build())
    }
    fun getAppInfo():Map<String,String>{
        var map :MutableMap<String,String> = mutableMapOf()
        map["model"] = Build.MODEL
        map["deviceType"] = "android"
        map["imei"] = MMKVConsts.oaid
        map["eaua"] = getUPID(CoreApplication.instance.baseContext)
        map["shangjia"] = MMKVConsts.shangjia
        return map
    }

}